<template>
  <a-card :bordered="false">
    <div style="display: flex; justify-content: space-between">
      <!-- 操作按钮区域 -->
      <div class="table-operator">
        <span>
          <a-button type="primary" icon="download" @click="handleExportXls('提现记录')">导出</a-button>
        </span>

        <a-dropdown v-if="selectedRowKeys.length > 0">
          <a-menu slot="overlay">
            <a-menu-item v-has="'withdraw:allPass'" @click="allPass"><a-icon type="delete" />批量审批</a-menu-item>
            <a-menu-item v-has="'withdraw:allFirsttrial'" @click="alInitialAllPass"
              ><a-icon type="delete" />批量初审</a-menu-item
            >
          </a-menu>
          <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
        </a-dropdown>
      </div>
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-form-item label="提现类型" style="margin-right: 10px">
            <a-select
              v-model="queryParam.withdrawalType"
              style="width: 120px"
              :options="options"
              allowClear
              placeholder="请选择"
              @change="searchQuery"
            />
          </a-form-item>
          <a-form-item label="城市服务商" style="margin-right: 10px">
            <serveSelect @selectClick="selectClick" :value="queryParam.agencyCode"></serveSelect>
          </a-form-item>
          <!--          状态（1通过，0待审核，2驳回 3待审批）-->
          <a-form-item label="审核状态" style="margin-right: 10px">
            <a-select
              v-model="queryParam.status"
              style="width: 120px"
              :options="[
                { label: '待初审', value: '0' },
                { label: '已通过', value: '1' },
                { label: '已驳回', value: '2' },
                { label: '待审批', value: '3' }
              ]"
              allowClear
              placeholder="请选择"
              @change="searchQuery"
            />
          </a-form-item>
          <a-form-item label="技师编号" style="margin-right: 10px">
            <a-input placeholder="请输入用户编号" v-model="queryParam.coachId" @pressEnter="searchQuery"></a-input>
          </a-form-item>
          <a-form-item label="服务技师" style="margin-right: 10px">
            <a-input placeholder="请输入服务技师" v-model="queryParam.coachName" @pressEnter="searchQuery"></a-input>
          </a-form-item>
          <a-form-item label="开始时间" style="margin-right: 10px">
            <a-date-picker v-model="queryParam.startTime" @change="startChange" :valueFormat="'YYYY-MM-DD'" />
          </a-form-item>
          <a-form-item label="结束时间" style="margin-right: 10px">
            <a-date-picker
              v-model="queryParam.endTime"
              @change="endChange"
              :valueFormat="'YYYY-MM-DD'"
              :disabled-date="disabledDate"
            />
          </a-form-item>
          <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
            <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
            <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
          </span>
        </a-form>
      </div>
    </div>
    <!-- table区域-begin -->
    <div class="ant-alert ant-alert-info" style="margin-bottom: 15px">
      <span style="margin-right: 20px"
        >已转帐金额：<span style="font-size: 16px; color: red">{{ parseFloat(isWithdrawAmount || 0).toFixed(2) }} </span
        >元</span
      >
      <span style="margin-right: 20px"
        >待转帐金额：<span style="font-size: 16px; color: red"
          >{{ parseFloat(notWithdrawAmount || 0).toFixed(2) }} </span
        >元</span
      >
    </div>
    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      class="j-table-force-nowrap"
      :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
      @change="handleTableChange"
    >
      <span slot="action" slot-scope="text, record">
        <div v-if="record.withdrawalStatus == 0">
          <a v-if="record.status == 0" @click="firsttrial(record)" v-has="'withdraw:allInitialAllPass'">初审</a>
          <a-divider v-if="record.status == 0" type="vertical" v-has="'withdraw:allInitialAllPass'" />

          <a-popconfirm
            v-if="record.status == 3"
            v-has="'withdraw:accounts'"
            title="确定通过吗?"
            @confirm="() => handlePass(record.id)"
          >
            <a>审批</a>
            <a-divider type="vertical" />
          </a-popconfirm>

          <a-popconfirm v-if="record.status === 0||record.status === 3" v-has="'withdraw:reject'" title="确定驳回吗?" @confirm="() => handleReject(record.id)">
            <a>驳回</a>
          </a-popconfirm>
        </div>
      </span>
    </a-table>

    <xhdjFirsttrial ref="firsttrial" @ok="modalFormOk"></xhdjFirsttrial>

    <!-- table区域-end -->
    <!-- 表单区域 -->
    <!-- <xhdjOrderInfo-modal ref="modalForm" @ok="modalFormOk"></xhdjOrderInfo-modal> -->
    <!-- <XhdjOrderInfoDialog ref="dialogForm"></XhdjOrderInfoDialog> -->
  </a-card>
</template>

<script>
import xhdjFirsttrial from './modules/xhdjFirsttrial.vue'
import '@/assets/less/TableExpand.less'
import serveSelect from '@/components/serveSelect.vue'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getAction } from '@api/manage'
// import XhdjOrderInfoDialog from './modules/XhdjOrderInfoDialog.vue'
export default {
  name: 'xhdjWithdrawalList',
  mixins: [JeecgListMixin],
  components: {
    serveSelect,
    xhdjFirsttrial
  },
  data () {
    return {
      description: '订单表管理页面',
      options: [
        { label: '车费', value: '0' },
        { label: '服务', value: '1' },
        { label: '返佣', value: '2' }
      ],
      isWithdrawAmount: 0,
      notWithdrawAmount: 0,
      typeW: 2,
      // 表头
      columns: [
        {
          title: '城市服务商',
          align: 'center',
          dataIndex: 'agencyName'
        },
        {
          title: '技师编号',
          align: 'center',
          dataIndex: 'coachId'
        },
        {
          title: '真实姓名',
          align: 'center',
          dataIndex: 'realName'
        },
        {
          title: '技师昵称',
          align: 'center',
          dataIndex: 'coachName'
        },
        // {
        //   title: '技师电话',
        //   align: 'center',
        //   dataIndex: 'createBy'
        // },
        {
          title: '提现类型',
          align: 'center',
          dataIndex: 'withdrawalType',
          customRender: (text, record) => {
            return this.options[record.withdrawalType].label
          }
        },
        {
          title: '提现金额（元）',
          align: 'center',
          dataIndex: 'amount'
        },
        {
          title: '扣费金额（元）',
          align: 'center',
          dataIndex: 'deductMoney'
        },
        {
          title: '扣费说明',
          align: 'center',
          dataIndex: 'deductExplains'
        },
        {
          title: '实际到账(元)',
          align: 'center',
          dataIndex: 'actualAmount'
        },
        {
          title: '开户行名称',
          align: 'center',
          dataIndex: 'bankBranchName'
        },
        {
          title: '持卡人姓名',
          align: 'center',
          dataIndex: 'cardholderName'
        },
        {
          title: '银行机构名称',
          align: 'center',
          dataIndex: 'bankName'
        },
        {
          title: '卡号',
          align: 'center',
          dataIndex: 'cardNumber'
        },
        // 状态（1通过，0待审核，2驳回3待审批）
        {
          title: '审批状态',
          align: 'center',
          dataIndex: 'status',
          customRender: (text, record) => {
            switch (record.status) {
              case 0:
                return '待初审'
                break
              case 1:
                return '已通过'
                break
              case 2:
                return '被驳回'
                break
              case 3:
                return '待审批'
                break
            }
          }
        },
        {
          title: '创建日期',
          align: 'center',
          dataIndex: 'createTime'
        },
        {
          title: '初审人员',
          align: 'center',
          dataIndex: 'firstBy'
        },
        {
          title: '复审人员',
          align: 'center',
          dataIndex: 'recheckBy'
        },
        {
          title: '更新时间',
          align: 'center',
          dataIndex: 'updateTime'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          width: 150,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/coach/xhdjCoachWithdrawal/list',
        delete: '/xhdjOrderInfo/delete',
        passUrl: '/coach/xhdjCoachWithdrawal/pass',
        allPassUrl: '/coach/xhdjCoachWithdrawal/allPass',
        alInitialAllPassUrl: '/coach/xhdjCoachWithdrawal/allInitialAllPass',
        reject: '/coach/xhdjCoachWithdrawal/reject',
        statistics: '/coach/xhdjCoachWithdrawal/statistics',
        exportXlsUrl: '/coach/xhdjCoachWithdrawal/exportXls'
      }
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  created () {
    this.init()
  },
  methods: {
    init () {
      this.getWeekday()
      var params = this.getQueryParams() //查询条件
      getAction(this.url.statistics, params).then(res => {
        if (res.success && res.result) {
          let { isWithdrawAmount, notWithdrawAmount } = res.result
          this.isWithdrawAmount = isWithdrawAmount
          this.notWithdrawAmount = notWithdrawAmount
        } else {
          this.isWithdrawAmount = 0
          this.notWithdrawAmount = 0
        }
      })
    },

    getWeekday () {
      const date = new Date()
      const days = ['(周日)', '(周一)', '(周二)', '(周三)', '(周四)', '(周五)', '(周六)']
      const weekday = days[date.getDay()]
    },
    selectClick (value) {
      this.queryParam.agencyCode = value
      this.searchQuery()
    },
    startChange (value) {
      if (value) {
        this.queryParam.startTime = value + ' 00:00:00'
      } else {
        this.queryParam.startTime = value
      }
    },
    endChange (value) {
      if (value) {
        this.queryParam.endTime = value + ' 23:59:59'
      } else {
        this.queryParam.endTime = value
      }
    },
    disabledDate (time) {
      return new Date(time).getTime() < new Date(this.queryParam.startTime).getTime()
    },
    firsttrial (record) {
      this.$refs.firsttrial.edit(record)
      this.$refs.firsttrial.title = '初审'
    },
    // 通过
    handlePass (id) {
      getAction(this.url.passUrl, { id }).then(res => {
        if (res.code == 200) {
          this.$message.success(res.message)
          this.loadData()
        } else {
          this.$message.console.error(res.message)
        }
      })
    },
    handleReject (id) {
      getAction(this.url.reject, { id }).then(res => {
        if (res.code == 200) {
          this.$message.success(res.message)
          this.loadData()
        } else {
          this.$message.console.error(res.message)
        }
      })
    },
    allPass () {
      console.log('批量通过')
      var ids = ''
      for (var a = 0; a < this.selectedRowKeys.length; a++) {
        ids += this.selectedRowKeys[a] + ','
      }
      this.$confirm({
        title: '通过',
        content: '确定通过选中的记录?',
        onOk: () => {
          this.loading = true
          getAction(this.url.allPassUrl, { ids }).then(res => {
            if (res.code === 200) {
              this.$message.success(res.message)
              this.loadData()
            } else {
              this.$message.error(res.message)
            }
          })
        }
      })
    },
    alInitialAllPass () {
      console.log('批量初审')
      var ids = ''
      for (var a = 0; a < this.selectedRowKeys.length; a++) {
        ids += this.selectedRowKeys[a] + ','
      }
      this.$confirm({
        title: '通过',
        content: '确定通过选中的记录?',
        onOk: () => {
          this.loading = true
          getAction(this.url.alInitialAllPassUrl, { ids }).then(res => {
            if (res.code === 200) {
              this.$message.success(res.message)
              this.loadData()
            } else {
              this.$message.error(res.message)
            }
          })
        }
      })
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
.ant-row {
  display: flex;
  justify-content: flex-end;
}
.ant-col {
  display: flex;
  justify-content: flex-end;
}
.ant-form {
  display: flex;
}
</style>
